//
//  USFensHeaderView.m
//  us
//
//  Created by karry on 2025/5/6.
//

#import "USFensHeaderView.h"

@implementation USFensHeaderView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backgroundColor = UIColor.clearColor;

    
    NSString *text = @"成为Us粉丝";
    NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text];
    
  
    NSTextAttachment *spaceAttachment = [[NSTextAttachment alloc] init];
    spaceAttachment.bounds = CGRectMake(0, 0, 4, 1);  // 宽4pt，高随便给1pt
    NSAttributedString *spaceAttrString = [NSAttributedString attributedStringWithAttachment:spaceAttachment];

    [attributedText appendAttributedString:spaceAttrString];
 
    NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
    attachment.image = [UIImage imageNamed:@"ic_love_red"];
    attachment.bounds = CGRectMake(0, -3, 16, 16);
    NSAttributedString *imageAttrString = [NSAttributedString attributedStringWithAttachment:attachment];

    [attributedText appendAttributedString:imageAttrString];

    self.lab0.attributedText = attributedText;
    
    
    //
    UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(platformTapAction:)];
    self.xhsView.tag = 1001;
    [self.xhsView addGestureRecognizer:tapGesture1];
    self.xhsView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(platformTapAction:)];
    self.dyView.tag = 1002;
    [self.dyView addGestureRecognizer:tapGesture2];
    self.dyView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tapGesture3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(platformTapAction:)];
    self.ksView.tag = 1003;
    [self.ksView addGestureRecognizer:tapGesture3];
    self.ksView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tapGesture4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(platformTapAction:)];
    self.biliView.tag = 1004;
    [self.biliView addGestureRecognizer:tapGesture4];
    self.biliView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tapGesture5 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(platformTapAction:)];
    self.wechatView.tag = 1005;
    [self.wechatView addGestureRecognizer:tapGesture5];
    self.wechatView.userInteractionEnabled = YES;
}

- (void)platformTapAction:(UITapGestureRecognizer *)gesture {
    [USFeedbackTool impactMedium];
    
    NSInteger tag = gesture.view.tag;
    
    NSString *urlString = nil;
    
    if (tag == 1001) {
        urlString = @"https://www.xiaohongshu.com/user/profile/654d8d640000000008002bcc?m_source=pwa";
    }else if (tag == 1002){
        urlString = @"https://v.douyin.com/l8BJTbncL50";
    }else if (tag == 1003){
        urlString = @"https://v.kuaishou.com/2Ah33Iy";
    }else if (tag == 1004){
        urlString = @"https://b23.tv/z80j0JA";
    }else if (tag == 1005){
        UIPasteboard.generalPasteboard.string = @"us_appwechat";
        [self.window makeToast:@"微信号已复制"];
    }
    
    if (urlString.length > 0) {
        NSURL *url = [NSURL URLWithString:urlString];
        [[UIApplication sharedApplication]openURL:url options:@{} completionHandler:nil];
    }
    
    
}
@end
